//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __RENDERLIB_CORE_H__
#define __RENDERLIB_CORE_H__

#include <elatypes.h>
using namespace Elastos;

#ifdef __cplusplus
extern "C" {
#endif


////////////////////////////////////////////////////////////////////////////
//  Names:              RGB24Blit2RGB24
//                      ARGB32Blit2RGB24
//                      RGB24Blit2ARGB32
//                      ARGB32Blit2ARGB32
//                      A8Blit2RGB24
//                      A8Blit2ARGB32
//
//  Purpose:            Blit source content block to destination buffer.
//
//  Parameters:
//      src             pointer to source buffer
//      dst             pointer to destination buffer
//      srcX            x coordinate of block start in srcBuffer
//      srcY            y coordinate of block start in srcBuffer
//      dstX            x coordinate of block start in dstBuffer
//      dstY            y coordinate of block start in dstBuffer
//      srcPitch        source buffer byte width
//      dstPitch        destination buffer byte width
//      width           block width
//      height          block height
//      srcOpacity      source block opacity, 255 means opaque
//      srcColor        specify source buffer(A8 format) with given color
//
//  Return:             none
//
//  Note:               Caller is responsible for buffer validity checking.
//
////////////////////////////////////////////////////////////////////////////
Void RGB24Blit2RGB24(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height,
                Int32 srcPitch, UInt8 srcOpacity);

Void ARGB32Blit2RGB24(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height,
                Int32 srcPitch, UInt8 srcOpacity);

Void RGB24Blit2ARGB32(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height,
                Int32 srcPitch, UInt8 srcOpacity);

Void ARGB32Blit2ARGB32(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height,
                Int32 srcPitch, UInt8 srcOpacity);

Void A8Blit2RGB24(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height,
                Int32 srcPitch, Color srcColor, UInt8 srcOpacity);

Void A8Blit2ARGB32(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height,
                Int32 srcPitch, Color srcColor, UInt8 srcOpacity);


////////////////////////////////////////////////////////////////////////////
//  Names:              SetColorARGB32
//                      FillColorOverDst
//
//  Purpose:            Set the Color to destination buffer.
//  SetColorARGB32      Clear the Destination Buffer with the srcColor
//  BlendColor          Blend to the Destination with srcColor,
//                      and Alpha Blit is done if the alpha of srcColor is not 0xFF
//  Parameters:
//      dst             pointer to destination buffer
//      dstX            x coordinate of block start in dstBuffer
//      dstY            y coordinate of block start in dstBuffer
//      dstPitch        destination buffer byte width
//      width           block width
//      height          block height
//      srcOpacity      source block opacity, 255 means opaque
//      srcColor        specify source buffer(A8 format) with given color
//
//  Return:             none
//
//  Note:               Caller is responsible for buffer validity checking.
//
////////////////////////////////////////////////////////////////////////////

Void SetColorARGB32(
                Address dst, Int32 dstX, Int32 dstY, Int32 width, Int32 height,
                Int32 dstPitch, Color srcColor, UInt8 srcOpacity);

Void BlendColor(
                Address dst, Int32 dstX, Int32 dstY, Int32 width, Int32 height,
                Int32 dstPitch, Color srcColor, UInt8 srcOpacity);


////////////////////////////////////////////////////////////////////////////
//  Names:              RGB24StretchBlit2RGB24
//                      ARGB32StretchBlit2RGB24
//                      RGB24StretchBlit2ARGB32
//                      ARGB32StretchBlit2ARGB32
//                      A8StretchBlit2RGB24
//                      A8StretchBlit2ARGB32
//
//  Purpose:            Blit source content block to destination buffer
//                      with stretching.
//
//  Parameters:
//      src             pointer to source buffer
//      dst             pointer to destination buffer
//      srcX            x coordinate of block start in srcBuffer
//      srcY            y coordinate of block start in srcBuffer
//      dstX            x coordinate of block start in dstBuffer
//      dstY            y coordinate of block start in dstBuffer
//      srcPitch        source buffer byte width
//      dstPitch        destination buffer byte width
//      srcWidth        source block width
//      srcHeight       source block height
//      dstWidth        destination block width
//      dstHeight       destination block height
//      srcOpacity      source content opacity, 255 means opaque
//      srcColor        specify source buffer(A8 format) with given color
//      interpolation   interpolation method 0:nearest neighbor
//                                           1:bilinear interpolation
//
//  Return:             none
//
//  Note:               Caller is responsible for buffer validity checking.
//
////////////////////////////////////////////////////////////////////////////
Void RGB24StretchBlit2RGB24(
                Address dst, Int32 dstX, Int32 dstY,
                Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY,
                Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                UInt8 srcOpacity,
                UInt8 interpolation);

Void ARGB32StretchBlit2RGB24(
                Address dst, Int32 dstX, Int32 dstY,
                Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY,
                Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                UInt8 srcOpacity,
                UInt8 interpolation);

Void RGB24StretchBlit2ARGB32(
                Address dst, Int32 dstX, Int32 dstY,
                Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY,
                Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                UInt8 srcOpacity,
                UInt8 interpolation);

Void ARGB32StretchBlit2ARGB32(
                Address dst, Int32 dstX, Int32 dstY,
                Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY,
                Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                UInt8 srcOpacity,
                UInt8 interpolation);

Void A8StretchBlit2RGB24(
                Address dst, Int32 dstX, Int32 dstY,
                Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY,
                Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                UInt8 srcOpacity,
                UInt8 interpolation,
                Color srcColor);

Void A8StretchBlit2ARGB32(
                Address dst, Int32 dstX, Int32 dstY,
                Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address  src, Int32 srcX, Int32 srcY,
                Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                UInt8 srcOpacity,
                UInt8 interpolation,
                Color srcColor);


////////////////////////////////////////////////////////////////////////////
//  Names:              RGB24ToRGB555
//                      RGB24ToRGB565
//                      RGB24ToRGB666
//
//  Purpose:            Convert color format of source block from RGB24 to
//                      RGB555,565,666 with rotation.
//
//  Parameters:
//      src             source buffer description struct
//      dst             destination buffer description struct
//      region          region in source buffer to convert
//      orientation     0:ScreenOrientation_Up    1:ScreenOrientation_Left
//                      2:ScreenOrientation_Down  3:ScreenOrientation_Right
//
//  Return:             none
//
//  Note:               srcBuffer and dstBuffer must be with the same width and
//                      height, if orientation is left or right, then width of
//                      srcBuffer equals the height of dstBuffer.
//                      The region specified cannot be larger than srcBuffer size.
//
////////////////////////////////////////////////////////////////////////////
Void RGB24ToRGB555(
                Address dst, Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcPitch,
                Int32 x, Int32 y, Int32 width, Int32 height,
                Int32 orientation);

Void RGB24ToRGB565(
                Address dst, Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcPitch,
                Int32 x, Int32 y, Int32 width, Int32 height,
                Int32 orientation);

Void RGB24ToRGB666(
                Address dst, Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcPitch,
                Int32 x, Int32 y, Int32 width, Int32 height,
                Int32 orientation);

Void RGB24ToRGB888(
                Address dst, Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcPitch,
                Int32 x, Int32 y, Int32 width, Int32 height,
                Int32 orientation);


Void A8Blit2A8WithOrientation(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height, Int32 srcPitch,
                Int32 orientation);

Void RGB24Blit2RGB24WithOrientation(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height, Int32 srcPitch,
                Int32 orientation);

Void ARGB32Blit2ARGB32WithOrientation(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height, Int32 srcPitch,
                Int32 orientation);


////////////////////////////////////////////////////////////////////////////
//  Names:              Rotate
//
//  Purpose:            Rotate a Image
//
//  Parameters:
//      dst             the image of destination
//      src             the image of Source
//      RotaryAngle     the Angle of  which be Rotated
//      ZoomX           the Zoom percent of in X-Direct
//      ZoomY           the Zoom percent of in Y-Direct
//      move_x          the offset in X-Direct
//      move_y          the offset in Y-Direct
//  Return:             None
//
//  Note:
//
////////////////////////////////////////////////////////////////////////////
Void Rotate(
            const BitmapBufInfo &dst, const BitmapBufInfo &src,
            double RotaryAngle, double ZoomX, double ZoomY,
            double move_x, double move_y);


////////////////////////////////////////////////////////////////////////////
//  Names:              Warp
//                      DrawAALine
//
//  Purpose:            Draw a/an (anti-aliasied) line in specified buffer
//
//  Parameters:
//      startX          line start position x
//      startY          line end position y
//      endX            line start position x
//      endY            line end position y
//      color           line color
//      img             bitmap buffer to draw
//
//  Return:             none
//
//  Note:
//
////////////////////////////////////////////////////////////////////////////
Void WarpPerspective_8u_C4A(
            const BitmapBufInfo& Src, const BitmapBufInfo& Dst, Int32 nWidth,
            Int32 nLHeight, Int32 nRHeight);

Void WarpPerspectiveH_8u_C4A(
            const BitmapBufInfo& Src, const BitmapBufInfo& Dst,
            Int32 nWidthT, Int32 nWidthD,
            Int32 nHeight);

Void ShearBilinear_8u_C4A(
            const BitmapBufInfo& Src, const BitmapBufInfo& Dst,
            Int32 offset);

Void CurveBilinear_8u_C4A(
            const BitmapBufInfo& Src, const BitmapBufInfo& Dst,
            Int32* aSampleX16,
            Int32 width);

////////////////////////////////////////////////////////////////////////////
//  Names:              DrawAAPolygon
//                      GradientFillColor
//
//  Purpose:            Draw a/an (anti-aliasied) line in specified buffer
//
//  Parameters:
//      startX
//      startY
//      endX
//      endY
//      color
//      img
//
//  Return:             none
//
//  Note:
//
////////////////////////////////////////////////////////////////////////////
Void DrawAAPolygon(
            Point * leftVertexList, Int32 LEdgeNum,
            Point * rightVertexList, Int32 REdgeNum,
            const BitmapBufInfo * srcImg, const BitmapBufInfo * dstImg,
            Int32 srcOpacity);

Void GradientFillColor(
            Int32* gradientTable,
            Int32 x0, Int32 y0,
            Int32 vx, Int32 vy,
            const BitmapBufInfo *img);

////////////////////////////////////////////////////////////////////////////
//  Names:              WaveSpread
//                      WaveRender
//
//  Purpose:            Draw a/an (anti-aliasied) line in specified buffer
//
//  Parameters:
//      startX          line start position x
//      startY          line end position y
//      endX            line start position x
//      endY            line end position y
//      color           line color
//      img             bitmap buffer to draw
//
//  Return:             none
//
//  Note:
//
////////////////////////////////////////////////////////////////////////////
//Void SinWave_32u(const _SINWAVE & sinwave);
//
//Void WaveSpread(short** pbuf1, short** pbuf2, Int32 width, Int32 height);
//Void WaveRender(short* buf1, short* buf2, BitmapBufInfo& src, BitmapBufInfo& dst);



////////////////////////////////////////////////////////////////////////////
//  Names:              RGB24DitherDown
//
//  Purpose:            PreDither Image to avoid color banding
//
//
//  Parameters:
//      pData           pointer to buffer for processing
//      width           buffer width
//      height          buffer height
//      RBit            dither red channel down to specified bit
//      GBit            dither green channel down to specified bit
//      BBit            dither blue channel down to specified bit
//
//  Return:             none
//
//  Note:               The buffer for processing will be both src and dst buffer,
//                      so make a backup if the original data is needed.
//                      The processed buffer is still RGB24 format, with lower bits
//                      clean out, these info will contribute to higher bits.
//
////////////////////////////////////////////////////////////////////////////
//Void RGB24DitherDown(Address data,
//                    Int32 width, Int32 height,
//                    Int32 Rbit, Int32 Gbit, Int32 Bbit);



////////////////////////////////////////////////////////////////////////////
//  Names:              Reserved the function of old version in wmmx32
//
//
////////////////////////////////////////////////////////////////////////////
Void SetColorARGB32_Raw(
                Address dst, Int32 dstX, Int32 dstY, Int32 width, Int32 height,
                Int32 dstPitch, Color srcColor, UInt8 srcOpacity);

Void RGB24Blit2RGB24_Raw(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height,
                Int32 srcPitch, UInt8 srcOpacity);

Void ARGB32Blit2ARGB32_Raw(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height,
                Int32 srcPitch, UInt8 srcOpacity);

Void RGB24StretchBlit2RGB24_Raw(Address pSrc, Address pDst,
                Int32 srcPitch, Int32 dstPitch,
                Int32 srcWidth, Int32 srcHeight,
                Int32 dstWidth, Int32 dstHeight,
                UInt32 xrIntFloat_16,
                UInt32 yrIntFloat_16,
                UInt32 interpolation);

#ifdef __cplusplus
}
#endif

#endif  //__RENDERLIB_CORE_H__


